<!DOCTYPE html>
<html lang="zh-cn">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>javascript 阶段</title>
    <style>
        ul {
            height: 300px;
            background-color: #ccc;
            display: flex;
        }
        ul li {
            width: 100px;
            height: 100px;
            background-color: green;
            margin: 10px ;
        }
    </style>
</head>
<body>

    <ul>
        <li data-role="li">1</li>
        <li data-role="li">2</li>
        <li data-role="li">3</li>
        <li data-role="li">4</li>
    </ul>

    <script>
        document.querySelector("ul").onclick = function(e) {
            var ele = e.target;
            console.log(ele);
            if(ele.dataset.role == "li"){
                console.log("点击的是li标签");
            }
        }

        // 优点: 
        // 减少DOM操作 ,不需要循环dom,逐个绑定事件
        // 可以动态的绑定事件
        // 缺点:
        // 给事件源添加属性(标记) 区别事件触发点


    </script>
</body>
</html>